<?php

namespace App\Console\Commands;

use App\Jobs\FetchTtmjShowDetail;
use DB;
use Illuminate\Console\Command;

class SortFillTtmjShowDetail extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sort:ShowDetail';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '整理天天美剧详情';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $sql = "SELECT DISTINCT shows.id,shows.name_en,episodes.url_provider FROM shows JOIN episodes on shows.id = episodes.show_id where LENGTH(shows.detail) > 8 AND episodes.`provider` LIKE '%ttmj%'";
        $ttmjShows = DB::select($sql);

        foreach ($ttmjShows as $show){
            $job = New FetchTtmjShowDetail($show);
            dispatch($job);
        }

    }
}
